package com.conversationboard.controller.unregistered;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.conversationboard.controller.NewQuestion;
import com.conversationboard.model.Board;
import com.conversationboard.model.Boards;

@WebServlet(name="UnregisteredNewQuestionControllerServlet", urlPatterns="/unregistered/NewQuestionControllerServlet")
public class NewQuestionControllerServlet extends HttpServlet {

    private static final long serialVersionUID = 2650598842784312202L;


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        try {

            /* Make sure you're allowed to post unregistered */

            int boardId = Integer.parseInt(request.getParameter("boardId"));
            Board board = Boards.getBoard(boardId);

            if (board.isRequireRegistration()) {
                return;
            }

            NewQuestion newQuestion = new NewQuestion();
            newQuestion.doPost(request, response);

        } catch (NumberFormatException e) {
        } catch (SQLException e) {
            throw new ServletException(e);
        }

    }

}
